
#include "calculatorServer.hpp"
#include <memory>
#include "Log.hpp"
#include "Utility.hpp"

using namespace ns_Server;

//Resquest:  请求
//Response:  响应
ns_Protocol::Response calculator(ns_Protocol::Request &req)
{
    ns_Protocol::Response resp;
    switch (req._op)
    {
    case '+':
        resp._result = req._x + req._y;
        break;
    case '-':
        resp._result = req._x - req._y;

        break;
    case '*':
        resp._result = req._x * req._y;

        break;
    case '/':
        if(req._y == 0)
            resp._code = 1;
        else
            resp._result = req._x / req._y;
        break;
    case '%':
        if(req._y == 0)
            resp._code = 0;
        else
            resp._result = req._x % req._y;
        break;
    default:
        resp._code = 2;
    }
    return resp;
}

int main()
{
    std::unique_ptr<tcp_server> tsvr(new tcp_server(calculator));
    tsvr->ServerInit();
    tsvr->Start();
    return 0;
}